package com.bootdo.analyze.controller;

import com.bootdo.analyze.dao.ClientSellAIDao;
import com.bootdo.analyze.domain.ClientSellAIDO;
import com.bootdo.analyze.domain.GoodsSellAIDO;
import com.bootdo.analyze.service.ClientSellAIService;
import com.bootdo.analyze.service.GoodsSellAIService;
import com.bootdo.analyze.util.WeiDuUtil;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客户AI分析
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2020-03-02 10:02:27
 */
 
@Controller
@RequestMapping("/analyze/client")
public class ClientSellAIController {
	@Autowired
	private ClientSellAIService clientSellAIService;


	/**
	 * 客户销售波动
	 * @return
	 */
	@GetMapping("/clientfluctuate")
	@RequiresPermissions("analyze:clientsellFluctuate:clientfluctuate")
	String clientFluctuate(){
		return "analyze/clientsellFluctuate/clientfluctuate";
	}

	@ResponseBody
	@GetMapping("/clientfluctuatelist")
	@RequiresPermissions("analyze:clientsellFluctuate:clientfluctuate")
	public PageUtils clienlist(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<ClientSellAIDO> goodsList = clientSellAIService.getClientFluctuate(query);
		//int total = clientSellAIService.count(query);
		int total = goodsList.size();
		PageUtils pageUtils = new PageUtils(goodsList, total);
		return pageUtils;
	}

	@GetMapping("/clientfluctuatereport")
	String sellclientReportShows(){
		return "analyze/clientsellFluctuate/fluctuatereport";
	}



	/**
	 * 客户销售图表
	 * @param id
	 * @return
	 */
	@GetMapping("/fluctuatecharthtml/{id}")
	String post(@PathVariable("id") Integer id, Model model) {
		model.addAttribute("id",id);
		return "analyze/clientsellFluctuate/fluctuatechart";
	}


	@ResponseBody
	@RequestMapping("/clientfluctuatechart")
	public Map goodsListChart(@RequestParam Map<String, Object> params){

		List<WeiDuUtil> weiDuUtilList = clientSellAIService.getClientInfo(params);
		List<Integer> countWDList = new ArrayList<Integer>();
		List<Double> pricesWDList = new ArrayList<Double>();
		List<String>  businessDayList = new ArrayList<String>();
		for (WeiDuUtil weiDuUtil:weiDuUtilList){
			countWDList.add(weiDuUtil.getCountWD());
			pricesWDList.add(weiDuUtil.getPricesWD());
			businessDayList.add(weiDuUtil.getBusinessDay()+"月");
		}
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("countWDList",countWDList);
		map.put("pricesWDList",pricesWDList);
		map.put("businessDayList",businessDayList);
		return map;
	}


	/**
	 * 客户销售分析
	 * @return
	 */
	@ResponseBody
	@GetMapping("/clientselllist")
	public PageUtils clienSelllist(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<ClientSellAIDO> goodsList = clientSellAIService.getClientSell(query);
		int total = goodsList.size();
		PageUtils pageUtils = new PageUtils(goodsList, total);
		return pageUtils;
	}


	

	
}
